home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_46937.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  35 lines

  1. -- card: 46937 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. FUNCTION PROTOTYPES
  11.  
  12. Traditionally, C's absence of run-time type checking contributed to its efficiency and flexibility but could also be the source of much programming frustration.  When a value was passed as a function argument, its type was not converted automatically to the type expected by the function.  Thus a call to the sqrt() math library function of the form:
  13.  
  14.     result = sqrt(10);       /* incorrect if no ANSI C function prototype is given */
  15.  
  16. returned an incorrect result since an int argument was passed to a function expecting a double.
  17.  
  18. With the advent of function prototypes* in ANSI C (and TC and C++), automatic type conversion was extended to such cases.  That is, by stating the types of the arguments expected by a function before that function is called, a function prototype gives the compiler enough information to provide the needed type conversion.
  19.  
  20.  
  21. -- part contents for background part 29
  22. ----- text -----
  23. 12248
  24.  
  25. -- part contents for background part 27
  26. ----- text -----
  27. Function prototypes
  28.  
  29. -- part contents for background part 20
  30. ----- text -----
  31. Function prototypes - p84
  32.  
  33. -- part contents for background part 7
  34. ----- text -----
  35. 149